# -*- coding: utf-8 -*-
# @Time : 2021/9/10 20:50
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : get_cookie.py
# @Project : crm

from selenium.webdriver.common.by import By
from driver.driver import chrome
#定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_locator=(By.NAME,"submit")
def cookie(HOST,name,password):
    '''登录网站并赋予令牌'''
    driver = chrome()
    driver.get(HOST)
    driver.find_element(*username_locator).send_keys(name)
    driver.find_element(*password_locator).send_keys(password)
    driver.find_element(*login_locator).click()
    cookies=driver.get_cookies()[0]
    cookie={}
    for k,v in cookies.items():
        if k=='name' or k=='value':
            cookie[k]=v
    driver.quit()
    return cookie
# cookie('http://192.168.1.140/crm3','admin','admin123')
